﻿<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:Rio_Framework_Pages_Controls="clr-namespace:Rio.Framework.Pages.Controls;assembly=Rio.Framework.Pages"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             xmlns:mvvmLightCommand="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.SL4"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             x:Class="Rio.Manager.Application.Views.ConnectorAddTabView"
             mc:Ignorable="d"
             d:DesignHeight="768"
             d:DesignWidth="1024">

    <!--Add connector page.-->
    
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../../Skins/ConnectorAddTabSkin.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
        <Style x:Key="BorderStyle1" TargetType="Border">
            <Setter Property="Effect">
                <Setter.Value>
                    <DropShadowEffect BlurRadius="10"/>
                </Setter.Value>
            </Setter>
            <Setter Property="Background" Value="#4CF9F9F9"/>
        </Style>
    </UserControl.Resources>

    <UserControl.DataContext>
        <Binding Path="ConnectorAddTab"
                 Source="{StaticResource Locator}" />
    </UserControl.DataContext>

    <!--Command initialization.-->
    <Grid x:Name="LayoutRoot">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="Loaded">
                <mvvmLightCommand:EventToCommand Command="{Binding InitializationCommand}" />
            </i:EventTrigger>
        </i:Interaction.Triggers>
        
    <!--Border-->
    <Border HorizontalAlignment="Center" 
            Padding="15,15,15,15" 
            Margin="230,0,230,0"
            VerticalAlignment="Center"  
            BorderBrush="Black" Style="{StaticResource BorderStyle1}" 
            Background="#FFF9F9F9">
        
        <Grid>
        <!--General grid definition-->
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
            <RowDefinition/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

       <!--View Add an connector-->
        
        <!--View title-->
        <TextBlock TextWrapping="Wrap"
                   Text="{Binding ConnectorTitleAdd}"
                   FontWeight="Bold"
                   HorizontalAlignment="Left"
                   Margin="0,10,0,10"/>
       
        <!--Control to select organization and folder type.-->
        <Rio_Framework_Pages_Controls:BindableOrganizationFolderTypePanel x:Name="UCOrganizationsFolderType"
                                                                          Mode="Admin"
                                                                          Margin="20,0,0,20"
                                                                          Grid.Row="1"
                                                                          HorizontalAlignment="Left"
                                                                          SelectedOrganization="{Binding SelectedOrganization, Mode=TwoWay}"
                                                                          SelectedFolderType="{Binding SelectedFolderType, Mode=TwoWay}"
                                                                          OrganizationLabel="{Binding OrganizationLabel}"
                                                                          FolderTypeLabel="{Binding FolderTypeLabel}"/>                                                                         
        
        <!--Controls connector generals informations-->
        <StackPanel Orientation="Vertical"
                    Grid.Row="2"
                    d:LayoutOverrides="Height"
                    Margin="0,0,0,0">
            
            <!--Separator between FolderType and Connector Name-->
            <Path Data="M62,141 L185.19902,141"
                  Fill="Black"
                  Stretch="Fill"
                  Stroke="Black"
                  UseLayoutRounding="False"
                  Margin="50,0"
                  StrokeThickness="0.5"/>

            <!--Connector name-->
            <TextBlock TextWrapping="Wrap"
                       Text="{Binding ConnectorGeneralInformationAddTitle}"
                       FontWeight="Bold"
                       HorizontalAlignment="Left"                   
                       Margin="0,20,0,10" />
            <TextBlock TextWrapping="Wrap"
                       Text="{Binding ConnectorNameAddTitle}"
                       FontWeight="Bold"
                       Margin="20,0,0,10"/>            
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="600"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <TextBox Grid.Row="0"
                         Grid.Column="0"
                         TextWrapping="Wrap"                     
                         Text="{Binding ConnectorNameAdd, Mode=TwoWay, NotifyOnValidationError=False}"                     
                         Margin="20,0,0,20"
                         MaxLength="25"/>
            </Grid>

            <!--Connector description-->
            <TextBlock TextWrapping="Wrap"
                       Text="{Binding ConnectorDescriptionAddTitle}"
                       FontWeight="Bold"
                       Margin="20,0,0,10"/>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="600"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <TextBox Grid.Row="0"
                         Grid.Column="0"
                         TextWrapping="Wrap"
                         Text="{Binding ConnectorDescriptionAdd, Mode=TwoWay, NotifyOnValidationError=False}"
                         Margin="20,0,0,20"
                         AcceptsReturn="True"
                         Height="60"/>
            </Grid>
        </StackPanel>

        <!--Connector correspondence-->
        <StackPanel Orientation="Vertical"
                    Grid.Row="3"
                    d:LayoutOverrides="Height"
                    Margin="0,0,0,0">
            
            <!--Separator between connector generals informations and Connector correspondences-->
            <Path Data="M62,141 L185.19902,141"
                  Fill="Black"
                  Stretch="Fill"
                  Stroke="Black"
                  UseLayoutRounding="False"
                  Margin="50,0"
                  StrokeThickness="0.5"/>

            <TextBlock TextWrapping="Wrap"                       
                       Text="{Binding ConnectorCorrespondencesAddTitle}"
                       FontWeight="Bold"
                       Margin="0,20,0,10"/>

            <!--Connector correspondence radgridview.-->
            <telerik:RadGridView x:Name="radGridView_Correspondences_Add"
                                 ItemsSource="{Binding ConnectorCorrespondenceList}"
                                 SelectionMode="Extended"
                                 AutoGenerateColumns="False"
                                 Margin="20,10,30,20"
                                 Grid.Row="1"
                                 ActionOnLostFocus="None"
                                 CanUserDeleteRows="{Binding IsChecked, Mode=TwoWay, ElementName=CanUserDeleteRowsCheckBox}"
                                 IsReadOnly="{Binding IsChecked, Mode=TwoWay, ElementName=IsReadOnlyCheckBox}"
                                 SelectionChanged="radGridView_Correspondences_Add_SelectionChanged"
                                 CanUserInsertRows="False"
                                 CanUserResizeColumns="True">              
                
                <telerik:RadGridView.Columns>                    

                    <telerik:GridViewSelectColumn />

                    <telerik:GridViewDataColumn Header="{Binding ConnectorAddTab.HeaderCorrespondenceIndexName, Source={StaticResource Locator}, Mode=TwoWay}"
                                                DataMemberBinding="{Binding ConnectorIndexCorrespondenceName, Mode=TwoWay}"
                                                IsReadOnly="True" />
                    <telerik:GridViewDataColumn Header="{Binding ConnectorAddTab.HeaderCorrespondenceIndexPosition, Source={StaticResource Locator}, Mode=TwoWay}"
                                                DataMemberBinding="{Binding ConnectorIndexCorrespondencePosition}"
                                                IsReadOnly="True"/>
                    <telerik:GridViewDataColumn Header="{Binding ConnectorAddTab.HeaderCorrespondenceIndexDescription, Source={StaticResource Locator}, Mode=TwoWay}"
                                                DataMemberBinding="{Binding ConnectorIndexCorrespondenceDescription}" />
                </telerik:RadGridView.Columns>                
            </telerik:RadGridView>
        </StackPanel>

        <StackPanel Orientation="Vertical"
                    Grid.Row="4"
                    d:LayoutOverrides="Height"
                    Margin="0,0,0,0">

            <!--Separator between connector correspondence and Connector parameters-->
            <Path Data="M62,141 L185.19902,141"
                  Fill="Black"
                  Stretch="Fill"
                  Stroke="Black"
                  UseLayoutRounding="False"
                  Margin="50,0"
                  StrokeThickness="0.5" />
            
            <!--Connector parameters-->
            <TextBlock TextWrapping="Wrap"
                       Text="{Binding ConnectorParametersAddTitle}"
                       FontWeight="Bold"
                       Margin="0,20,0,10"/>            
            
            <!--Connector parameters radgridview-->
            <telerik:RadGridView x:Name="radGridView_Parameters_Add"
                                 ItemsSource="{Binding ConnectorParameterList}"
                                 SelectionMode="Extended"
                                 AutoGenerateColumns="False"
                                 Margin="20,10,30,20"
                                 Grid.Row="1"
                                 ActionOnLostFocus="None"
                                 CanUserInsertRows="True"
                                 CanUserDeleteRows="{Binding IsChecked, Mode=TwoWay, ElementName=CanUserDeleteRowsCheckBox}"
                                 CanUserFreezeColumns="False"
                                 RowIndicatorVisibility="Collapsed"
                                 RowValidated="radGridView_Parameters_Add_RowValidated"
                                 BeginningEdit="radGridView_Parameters_Add_BeginningEdit"
                                 CanUserResizeColumns="True"
                                 ShowInsertRow="True">                                 
                                 <i:Interaction.Triggers>
                                     <i:EventTrigger EventName="AddingNewDataItem">
                                         <mvvmLightCommand:EventToCommand Command="{Binding AddRowCommand}" />
                                     </i:EventTrigger>
                                 </i:Interaction.Triggers>
                
                <telerik:RadGridView.Columns>

                    <telerik:GridViewColumn>
                        <telerik:GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <telerik:RadButton Content="{Binding ConnectorAddTab.Button_Delete_Connector_Parameter, Source={StaticResource Locator}, Mode=TwoWay}"
                                                   Command="telerikGrid:RadGridViewCommands.Delete"
                                                   CommandParameter="{Binding}" />                                
                            </DataTemplate>                                
                        </telerik:GridViewColumn.CellTemplate> 
                    </telerik:GridViewColumn>

                            <telerik:GridViewColumn>
                                <telerik:GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <telerik:RadButton Content="{Binding ConnectorAddTab.Button_Validate_Connector_Parameter, Source={StaticResource Locator}, Mode=TwoWay}"
                                                   Command="telerikGrid:RadGridViewCommands.CommitEdit"
                                                   CommandParameter="{Binding}" />
                                    </DataTemplate>
                                </telerik:GridViewColumn.CellTemplate>
                            </telerik:GridViewColumn>

                            <telerik:GridViewDataColumn Header="{Binding ConnectorAddTab.HeaderParametersERP, Source={StaticResource Locator}, Mode=TwoWay}"
                                                DataMemberBinding="{Binding ConnectorCustomerParam}"/>
                    <telerik:GridViewDataColumn Header="{Binding ConnectorAddTab.HeaderParametersRIO, Source={StaticResource Locator}, Mode=TwoWay}"
                                                DataMemberBinding="{Binding ConnectorRioParam}"/>
                    <telerik:GridViewDataColumn Header="{Binding ConnectorAddTab.HeaderParametersDescription, Source={StaticResource Locator}, Mode=TwoWay}"
                                                DataMemberBinding="{Binding ConnectorDescriptionParam}"/>
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>
        </StackPanel>

        <StackPanel Orientation="Horizontal"
                    Grid.Row="5"
                    d:LayoutOverrides="Height"
                    Margin="0,0,0,0"
                    HorizontalAlignment="Right">
            
            <!--Add save connector button-->
            <Button x:Name="Button_Save"
                    Content="{Binding ConnectorAddTab.Button_Save_Connector, Source={StaticResource Locator},Mode=OneWay}"   
                    Margin="0,10,10,10"
                    Command="{Binding SaveConnector}"
                    IsEnabled="{Binding IsEnabledAddConnectorButton, Mode=TwoWay}"/>

            <!--Update connector button-->
            <Button x:Name="Button_Modify"
                    Content="{Binding ConnectorAddTab.Button_Update_Connector, Source={StaticResource Locator},Mode=OneWay}"
                    Margin="0,10,10,10"
                    Command="{Binding UpdateConnector}"
                    IsEnabled="{Binding IsEnabledUpdateConnectorButton, Mode=TwoWay}"/>
            
            <!--Button close-->
            <Button x:Name="Button_Close"
                    Content="{Binding ConnectorAddTab.Button_Close_Connector, Source={StaticResource Locator},Mode=OneWay}"
                    Margin="0,10,30,10"
                    Command="{Binding CloseConnector}" />
        </StackPanel>
    </Grid>
    </Border>
    </Grid>

</UserControl>
